package com.synjones.handsetS8.ild.net.api;

import com.google.gson.Gson;

import java.util.Map;

import okhttp3.MediaType;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.http.Body;
import retrofit2.http.POST;

/**
 * 测试用的
 */
public class IdCardApi {

    /**
     * 添加身份证信息
     *
     * @param idCardInfo
     */
    public static void addIdCard(Map<String, Object> idCardInfo) {
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl("http://192.168.101.138:8080/")
                .build();

        IdCardService service = retrofit.create(IdCardService.class);

        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), new Gson().toJson(idCardInfo));

        Call<ResponseBody> call = service.addIdCard(requestBody);

        call.enqueue(new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                System.out.println(response.body());
            }

            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {
                System.out.println("请求失败");
            }
        });
    }


    interface IdCardService {
        @POST("api/handset/addIdCard")
        Call<ResponseBody> addIdCard(@Body RequestBody body);
    }
}
